package com.lk.mall.service.impl;

import com.lk.mall.mapper.CarouselMapper;
import com.lk.mall.model.entity.Carousel;
import com.lk.mall.model.vo.MallCarouselVo;
import com.lk.mall.service.ICarouselService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lk.mall.util.BeanUtil;
import com.lk.mall.util.PageQueryUtil;
import com.lk.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lak
 * @since 2022-08-31
 */
@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements ICarouselService {
    @Autowired
    private CarouselMapper carouselMapper;

    // ---------------------------------------以下为商城系统代码------------------------------------------
    // 获取轮播图信息
    @Override
    public List<MallCarouselVo> getCarousels(int number) {
        List<MallCarouselVo> carouselVoList = new ArrayList<>(number);
        List<Carousel> carouselList = carouselMapper.findCarouselsByNumber(number);
        if (!CollectionUtils.isEmpty(carouselList)) {
            carouselVoList=BeanUtil.copyList(carouselList,MallCarouselVo.class);
        }
        return carouselVoList;
    }


    // ---------------------------------------以下为后台管理系统代码--------------------------------------
    @Override
    public PageResult<Carousel> getCarouselPage(PageQueryUtil pageQueryUtil) {
        List<Carousel> carousels = carouselMapper.findCarouselList(pageQueryUtil);
        int total = carouselMapper.getTotalCarousels(pageQueryUtil);
        return new PageResult<>(carousels, total, pageQueryUtil.getLimit(), pageQueryUtil.getPage());
    }
}
